package com.shop.controller;

import com.shop.entity.ShopCat;
import com.shop.entity.ShowPageT;
import com.shop.entity.User;
import com.shop.servlet.impl.ShopCatServletImpl;
import jakarta.servlet.annotation.WebServlet;

/**
 * com.shop.controller文档说明
 *
 * @author Angluzha
 * @version 2022/9/21
 */
@WebServlet("/shopcat/*")
public class ShopCatController extends BaseController<ShopCat>{
    {
        servlet = new ShopCatServletImpl();
    }
    public String save(ShopCat shopCat){
        try {
            shopCat.setUid(((User)req.getSession().getAttribute("user")).getId());
            ShopCatServletImpl servlet = (ShopCatServletImpl) this.servlet;
            return servlet.save(shopCat)?writeWeb("ok"):writeWeb("on");
        }catch (Exception e){
            return redirect("/login.jsp");
        }
    }

    public  String delete(ShopCat shopCat){
        servlet.deleteById(shopCat.getId());
        return redirect("/shopcat/check");
    }

    public String check(){
        ShowPageT<ShopCat> pageT = new ShowPageT<>();
        if (pageT!=null){
            pageT.setUid(((User)req.getSession().getAttribute("user")).getId());
        }
        page(pageT,"/shopcat/check");
            System.out.println(pageT.getUid());
        return forward("/shopcat.jsp");
    }
    public String revise(){
        Integer id = Integer.valueOf(req.getParameter("id"));
        Integer status = Integer.valueOf(req.getParameter("status"));
        ShopCatServletImpl servlet = (ShopCatServletImpl) this.servlet;
        return servlet.revise(id,status)?writeWeb("ok"):writeWeb("on");
    }
}
